using System;
using System.Collections.Generic;
using System.Text;
using Objects;

namespace DAL
{
    public class DALChuDe
    {
        public List<ChuDe> GetAllItem()
        {
            List<ChuDe> ListChuDe = new List<ChuDe>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString()};
            System.Data.DataSet ds = acc.CommandSelect("ChuDe_GetAllItem", sname, vname);

            ChuDe Item = new ChuDe();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListChuDe.Add((Item.Populate(dr)));
            }
            return ListChuDe;
        }

        public List<ChuDe> GetByIdMauThe(int IdMauThe)
        {
            List<ChuDe> ListChuDe = new List<ChuDe>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@IdMauThe" };
            string[] vname = new string[] { IdMauThe.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("ChuDe_GetByIdMauThe", sname, vname);

            ChuDe Item = new ChuDe();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListChuDe.Add((Item.Populate(dr)));
            }
            return ListChuDe;
        }

        

        public ChuDe GetByIdChuDe(int IdChuDe)
        {

            ChuDe Item = new ChuDe(); 
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id" };
            string[] vname = new string[] { IdChuDe.ToString()};
            System.Data.DataSet ds = acc.CommandSelect("ChuDe_GetByIdChuDe", sname, vname);
            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
            
        }


        public int Insert_ChuDe(String TenChuDe,String DuongDan,String GhiChu ,int SapXep)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@TenChuDe","@DuongDan","@GhiChu" ,"@Status", "@SapXep"};
            string[] vname = new string[] { TenChuDe.ToString(),DuongDan.ToString(),GhiChu.ToString(), Common.Myconst.HOATDONG.ToString(), SapXep.ToString()};
            return acc.InsertUpdateDetete("ChuDe_Insert", sname, vname);

        }

        public int Update_ChuDe(int id, String TenChuDe,String DuongDan,String GhiChu ,int Status, int SapXep)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id", "@TenChuDe", "@DuongDan","@GhiChu","@Status", "@SapXep" };
            string[] vname = new string[] { id.ToString(), TenChuDe.ToString(), DuongDan.ToString(),GhiChu.ToString() ,Status.ToString(), SapXep.ToString() };
            return acc.InsertUpdateDetete("ChuDe_Update", sname, vname);

        }

        public int Delete_ChuDe(int id)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@id" };
            string[] vname = new string[] { id.ToString() };
            return acc.InsertUpdateDetete("ChuDe_Delete", sname, vname);

        }
    }
}
